<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="msg"><br>
        <input type="text" v-model="deepObj.name"><br>
        <input type="text" v-model="userObj.name"><br>
    </div>
    <script src="js/vue.js"></script>
    <script>
        let vm = new Vue({
            el:"#app",
            data:{
                msg:"hello",
                deepObj:{name:"李四"},
                userObj:{name:"李四"},
            },
            computed:{
                newName(){
                    return this.userObj.name
                }
            },
            // 侦听
            watch:{
                msg(newval,oldval){
                    console.log(newval,oldval);
                },
                // 对象属性发生变化时,侦听不到
                // deepObj(newval,oldval){
                //     console.log(newval,oldval);
                // }
                deepObj:{
                    handler(newval,oldval){
                        console.log(newval.name,oldval.name);
                    },
                    // 深度侦听  默认是false , true表示深度侦听
                    deep:true  
                },
                newName(newval,oldval){
                    console.log(newval.name,oldval.name);
                }
            }
        })
    </script>
</body>
</html>